﻿CREATE PROCEDURE [acms].[Post_GetAllByTopicId]
	@SiteId int, 
	@TopicId int, 
	@SiteVersion datetime
AS
	declare @tmpVersion datetime
	
	set @tmpVersion = acms.GetPublishDate(@SiteId, @SiteVersion)
	
	if(@tmpVersion is null and @SiteVersion is not null)
		return 
	
	select a.*, c.[ParentPath] as ParentPath, c.PublishDate as SiteVersion
	From Post_View a
		inner join PostTopics b on a.Id = b.PostId and b.Deleted = 0
		inner join PostPositions c on a.Id = c.PostId and isNull(c.PublishDate, '9999/12/31') = isNull(@tmpVersion, '9999/12/31')
	Where b.TopicId = @TopicId
	Order by c.[ParentPath], a.Name

RETURN 0;